package com.zxlspace.collection2;

import javax.sound.midi.Soundbank;
import javax.swing.event.DocumentEvent;
import java.util.*;

/**
 * @author zhangxiaolin
 * @version V1.0
 * @Title: 测试迭代器
 * @Package
 * @Description: TODO
 * @date
 */
public class IteratorTest {

    public static void main(String[] args) {
        List list = new ArrayList();
        list.add("高一");
        list.add("高二");
        list.add("高三");

        //通过迭代器遍历
        for (Iterator iterator = list.iterator();iterator.hasNext();) {
            String str = (String) iterator.next();
            System.out.println(str);
        }

        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }

        Set<String> set = new HashSet<>();
        set.add("123");
        set.add("234");
        set.add("456");
        System.out.println("set size:" + set.size());

        LinkedList linkedList = new LinkedList();
        linkedList.add("111");
        linkedList.add("111");
        linkedList.add("111");


        for (Iterator iterator1 = linkedList.iterator();iterator1.hasNext();) {
            System.out.println("linkedlist:" + iterator1.next());
        }

        Map<String, Object> map = new HashMap();
        map.put("123", new Object());
        map.put("223", new Object());
        map.put("323", new Object());

        for (Object obj:map.values()) {
            System.out.println("map value:" + obj);
        }

        for (String str : map.keySet()) {
            System.out.println("map key:" + str);
        }
    }
}
